home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 1
/
Cream of the Crop 1.iso
/
PROGRAM
/
LDB171.ARJ
/
EXAMP502.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-12
|
2KB
|
67 lines
// examp502.cpp - link with binder.obj
// rework of examp402.cpp
#define sfile "examp502.txt"
#include <string.h>
#include <iostream.h>
#include "binder.hpp"
struct str {
char *s;
str(const char *cs = (char *)0) // default constructor
{ s = (cs? strdup(cs) : (char *)0); }
str(str& si) // copy initialize
{ s = (si.s? strdup(si.s) : si.s); }
void operator=(str& si) // assignment
{ delete s; s = (si.s? strdup(si.s) : si.s); }
~str() { delete s; } // destructor
};
ostream& operator<<(ostream& os, str& si)
{
int i = (si.s? strlen(si.s) : 0);
os << i << BDRendm;
if (i)
os.write(si.s,i);
return os;
}
istream& operator>>(istream& is, str& si)
{
char * D;
int i;
is >> i >> BDRnextm;
if ((D = new char[i+i]) != (char *)0) {
if (i)
is.read(D,i);
D[i] = '\0';
si.s = D;
}
return is;
}
#define FType str
#define FBinder StrBdr
#define FBindeR StrBdR
#include "fbinder.hpp"
main()
{
StrBdr sb(BDR_DDELETE | BDR_DNEW | BDR_DSTORE);
sb.ins(new str("line one"));
str s("line two");
sb.insNew(&s);
sb.save(sfile);
StrBdR sB = new StrBdr(sfile);
if (!sB) return 1;
sB->setCurNode(); // reset current node
while (sB->next()) cout << ((str *)*sB)->s << "\n";
delete sB;
return 0;
}